﻿namespace Services
{
    using System.Collections.Generic;
    using System.Linq;
    using DAL;
    using Entities;
    using System.Data.Objects;

    public class GenericFilesService : IGenericFilesService
    {
        #region Member Variables
        protected readonly IGenericRepository<FAEntities, AuditedOperation> repository;
        #endregion

        #region Constructor
        public GenericFilesService(IGenericRepository<FAEntities, AuditedOperation> repository)
        {
            this.repository = repository;
        }
        #endregion

        #region IGenericFilesService

        public  IEnumerable<AuditedOperation> SearchFileActions(FilterOperations filter)
        {
            var operations = from o in repository.Context.AuditedOperations
                             where o.OperationType == (short)filter.operationType
                             select o;
            return Common.FilterOperations(filter, ref operations);
        }

        public  IEnumerable<AuditedOperation> GetAll(OperationType operationType)
        {
            return repository.Find(o => o.OperationType == (short)operationType);
        }

        public IEnumerable<AuditedOperation> SearchOffHours(FilterOperations filter)
        {
            var operations = from o in repository.Context.AuditedOperations
                             where o.ReceivedTime.Value.Hour > 16 || o.ReceivedTime.Value.Hour < 9
                             select o;
            return Common.FilterOperations(filter, ref operations);
        }

        #endregion
    }
}